package com.example.photography.adapter.home_vlog;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.example.photography.R;
import com.example.photography.adapter.MyBaseAdapter;
import com.example.photography.bean.Vlog;
import com.example.photography.ui.CircleImageView;
import com.example.photography.util.UIUtils;
import com.example.photography.util.Util;
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class VlogAdapter extends MyBaseAdapter {

    public static final String TAG = "ListNormalAdapter22";

    public VlogAdapter(List list, Context context) {
        super(list, context);
    }

    @Override
    public void refresh(List lists) {
        super.refresh(lists);
    }

    @Override
    public View myGetView(int position, View convertView) {
        final ViewHolder holder;
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.item_video, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        //装配数据
        Vlog vlog = (Vlog) list.get(position);
        //glide头像加载实现
        Glide.with(UIUtils.getContext())
                .load(vlog.getHead_url())
                .thumbnail(Glide.with(UIUtils.getContext()).load(R.drawable.head_empty))
                .apply(RequestOptions.bitmapTransform(new RoundedCorners(30)))
                .into(holder.ivHead);
        holder.tvName.setText(vlog.getName());

        holder.video.setUp(vlog.getVlog_url(), true, null);
        //设置返回键
        holder.video.getTitleTextView().setVisibility(View.GONE);
        //设置全屏按键功能
        holder.video.getBackButton().setVisibility(View.GONE);
        //防止错位设置
        holder.video.setPlayTag(TAG);
        //一全屏就锁屏横屏
        holder.video.setLockLand(true);
        //是否开启自动旋转
        holder.video.setRotateViewAuto(true);
        //是否根据视频尺寸，自动选择竖屏全屏或者横屏全屏
//        holder.video.setAutoFullWithSize(false);
        //全屏动画
        holder.video.setShowFullAnimation(true);
        //设置全屏按键功能
        //增加封面
        ImageView imageView = new ImageView(mContext);
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        imageView.setImageResource(R.drawable.bg_image);
        holder.video.setThumbImageView(imageView);
        holder.video.getFullscreenButton().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                holder.video.startWindowFullscreen(mContext, false, true);
            }
        });

        holder.tvFocus.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Util.showToast(mContext,"点击了关注~");
//                LoadToast lt = new LoadToast(mContext);
//                lt.setText("Sending Reply...");
//                lt.setTranslationY(100);
//                lt.show();
            }
        });
        return convertView;

    }

    static
    class ViewHolder {
        @BindView(R.id.iv_head)
        CircleImageView ivHead;
        @BindView(R.id.tv_name)
        TextView tvName;
        @BindView(R.id.tv_focus)
        TextView tvFocus;
        @BindView(R.id.tv_title)
        TextView tvTitle;
        @BindView(R.id.rv_label)
        RecyclerView rvLabel;
        @BindView(R.id.video)
        StandardGSYVideoPlayer video;
        @BindView(R.id.iv_like)
        ImageView ivLike;
        @BindView(R.id.iv_comment)
        ImageView ivComment;
        @BindView(R.id.iv_collect)
        ImageView ivCollect;
        @BindView(R.id.iv_share)
        ImageView ivShare;
        @BindView(R.id.tv_likenum)
        TextView tvLikenum;
        @BindView(R.id.tv_commentnum)
        TextView tvCommentnum;
        @BindView(R.id.ll_content)
        LinearLayout llContent;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
